package com.bestcem.xm.ticket.enums;

import cn.hutool.core.util.ObjectUtil;

/**
 * 单选选项数据的来源
 *
 * @author xuan.yang <xuan.yang@idiaoyan.com>
 * @version v2.3
 * @date 2021/9/2 11:17
 */
public enum TemplateSelectSourceEnum {
    /**
     * 自定义
     */
    CUSTOMER_SOURCE(1, "自定义来源"),
    /**
     * 系统问卷数据
     */
    SYSTEM_SURVEY(2, "系统问卷数据"),
    /**
     * 系统联系人
     */
    SYSTEM_MEMBER(3, "系统联系人数据");
    private final Integer index;

    private final String name;

    TemplateSelectSourceEnum(Integer index, String name) {
        this.index = index;
        this.name = name;
    }

    public Integer getIndex() {
        return index;
    }

    /**
     * 根据 index 获取枚举实体
     * 找不到则返回 null
     *
     * @param index
     * @return
     */
    public static TemplateSelectSourceEnum getByIndex(Integer index) {
        for (TemplateSelectSourceEnum templateSelectSourceEnum : TemplateSelectSourceEnum.values()) {
            if (ObjectUtil.equal(templateSelectSourceEnum.index, index)) {
                return templateSelectSourceEnum;
            }
        }
        return null;
    }
}
